package utils.handlers;

import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;

import utils.style.WishExcelStyle;

public class LoopRowBoldWriteHandler implements CellWriteHandler
{
	private int loop = 0;

	private boolean fromFirst = false;

	private boolean useRelativeRow = true;

	public LoopRowBoldWriteHandler(int loop)
	{
		this.loop = loop;
	}

	public LoopRowBoldWriteHandler(int loop, boolean useRelativeRow)
	{
		this.loop = loop + 1;
		this.useRelativeRow = useRelativeRow;
	}

	public LoopRowBoldWriteHandler(int loop, boolean fromFirst, boolean useRelativeRow)
	{
		this.loop = loop + 1;
		this.useRelativeRow = useRelativeRow;
		this.fromFirst = fromFirst;
	}

	@Override
	public void afterCellDispose(CellWriteHandlerContext context)
	{
		int index = context.getRelativeRowIndex();
		if (!useRelativeRow)
		{
			index = context.getRowIndex() - context.getHeadData().getHeadNameList().size();
		}

		if (!fromFirst)
		{
			index = index + 1;
		}

		if (index % loop == 0)
		{
			context.getFirstCellData().setWriteCellStyle(WishExcelStyle.getWriteCellStyleBold());
		}
	}

}
